package cc.io24.knewcafe.boss.dao;

import cc.io24.knewcafe.boss.domain.SysPermission;
import cc.io24.knewcafe.boss.repository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(collectionResourceRel = "sysPermission", path = "sysPermission")
public interface SysPermissionDao extends BaseRepository<SysPermission, String> {

    @Query(value = "select DISTINCT permission_code from sys_permission  where id in \n" +
            "(select permission_id from sys_role_permission r_p where r_p.role_id in \n" +
            "(select role_id from sys_user_role as u_r where u_r.user_id in \n" +
            "(select id from sys_user where sys_user.username=:username ) ) ) ",nativeQuery = true)
    String[] findAllByUsername(@Param("username")String username);

}
